package com.intpro.demo.Controller;

import com.intpro.demo.DAO.CommonRep;
import com.intpro.demo.Utils.CodeException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class CommonExceptionHandler
{

	@ExceptionHandler(CodeException.class)
	@ResponseBody
	public CommonRep codeExceptionHandler(CodeException e)
	{
		CommonRep result = new CommonRep(e.code, e.getMessage());
		return result;

	}

	@ExceptionHandler(IllegalStateException.class)
	@ResponseBody
	public CommonRep illegalStateExceptionHandler(IllegalStateException e)
	{
		CommonRep result = new CommonRep(444, e.getMessage());
		return result;
	}

	@ExceptionHandler(Exception.class)
	@ResponseBody
	public CommonRep exceptionHandler(Exception e)
	{
		CommonRep result = new CommonRep(445, e.getMessage());
		return result;

	}
}